import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:hc_ui/config/hc_default_theme_config.dart';
import 'package:hc_ui/theme/hc_base_theme.dart';

import 'hc_common_theme.dart';

class HcEmptyTheme extends HcBaseTheme<HcEmptyTheme> {
  EdgeInsets? _padding;
  EdgeInsets? _imageMargin;
  EdgeInsets? _titleMargin;
  EdgeInsets? _descMargin;
  EdgeInsets? _imagePadding;
  EdgeInsets? _titlePadding;
  EdgeInsets? _descPadding;
  double? _buttonSpacing;
  Color? _backgroundColor;
  TextStyle? _titleTextStyle;
  TextStyle? _descTextStyle;

  HcEmptyTheme(
      {EdgeInsets? padding,
      EdgeInsets? imageMargin,
      EdgeInsets? titleMargin,
      EdgeInsets? descMargin,
      EdgeInsets? imagePadding,
      EdgeInsets? titlePadding,
      EdgeInsets? descPadding,
      double? buttonSpacing,
      Color? backgroundColor,
      TextStyle? titleTextStyle,
      TextStyle? descTextStyle})
      : _padding = padding,
        _imageMargin = imageMargin,
        _titleMargin = titleMargin,
        _descMargin = descMargin,
        _imagePadding = imagePadding,
        _titlePadding = titlePadding,
        _descPadding = descPadding,
        _buttonSpacing = buttonSpacing,
        _backgroundColor = backgroundColor,
        _titleTextStyle = titleTextStyle,
        _descTextStyle = descTextStyle;

  @override
  void initTheme({HcCommonTheme? tempTheme}) {
    super.initTheme(tempTheme: tempTheme);
    _padding ??= EdgeInsets.symmetric(
      vertical: commonTheme.vSpacingPage,
    );
    _imageMargin ??= EdgeInsets.only(bottom: commonTheme.vSpacingPage);
    _titleMargin ??= EdgeInsets.only(bottom: commonTheme.vSpacingSm);
    _descMargin ??= EdgeInsets.only(bottom: commonTheme.vSpacingSm);
    _imagePadding ??=
        EdgeInsets.symmetric(horizontal: commonTheme.hSpacingPage);
    _titlePadding ??=
        EdgeInsets.symmetric(horizontal: commonTheme.hSpacingPage);
    _descPadding ??= EdgeInsets.symmetric(horizontal: commonTheme.hSpacingPage);
    _buttonSpacing ??= commonTheme.vSpacingSm;
    _backgroundColor ??= commonTheme.fillWidgetColor;
    _titleTextStyle ??= TextStyle(
        color: commonTheme.textBaseColor,
        fontSize: commonTheme.fontSizeBase,
        height: commonTheme.fontHeightLg);
    _descTextStyle ??= TextStyle(
        color: commonTheme.textDisableColor,
        fontSize: commonTheme.fontSizeBase,
        height: commonTheme.fontHeightLg);
  }

  @override
  HcEmptyTheme merge(HcEmptyTheme? value) {
    if (value == null) return this;
    return copyWith(
      padding: value._padding,
      imageMargin: value._imageMargin,
      titleMargin: value._titleMargin,
      descMargin: value._descMargin,
      imagePadding: value._imagePadding,
      titlePadding: value._titlePadding,
      descPadding: value._descPadding,
      buttonSpacing: value._buttonSpacing,
      backgroundColor: value._backgroundColor,
      titleTextStyle: titleTextStyle.merge(value._titleTextStyle),
      descTextStyle: descTextStyle.merge(value._descTextStyle),
    );
  }

  HcEmptyTheme copyWith(
      {EdgeInsets? padding,
      EdgeInsets? imageMargin,
      EdgeInsets? titleMargin,
      EdgeInsets? descMargin,
      EdgeInsets? imagePadding,
      EdgeInsets? titlePadding,
      EdgeInsets? descPadding,
      double? buttonSpacing,
      Color? backgroundColor,
      TextStyle? titleTextStyle,
      TextStyle? descTextStyle}) {
    return HcEmptyTheme(
        padding: padding ?? _padding,
        imageMargin: imageMargin ?? _imageMargin,
        titleMargin: titleMargin ?? _titleMargin,
        descMargin: descMargin ?? _descMargin,
        imagePadding: imagePadding ?? _imagePadding,
        titlePadding: titlePadding ?? _titlePadding,
        descPadding: descPadding ?? _descPadding,
        buttonSpacing: buttonSpacing ?? _buttonSpacing,
        backgroundColor: backgroundColor ?? _backgroundColor,
        titleTextStyle: titleTextStyle ?? _titleTextStyle,
        descTextStyle: descTextStyle ?? _descTextStyle);
  }

  TextStyle get descTextStyle =>
      _descTextStyle ?? HcDefaultThemeConfig.defaultEmptyTheme.descTextStyle;

  TextStyle get titleTextStyle =>
      _titleTextStyle ?? HcDefaultThemeConfig.defaultEmptyTheme.titleTextStyle;

  Color get backgroundColor =>
      _backgroundColor ??
      HcDefaultThemeConfig.defaultEmptyTheme.backgroundColor;

  double get buttonSpacing =>
      _buttonSpacing ?? HcDefaultThemeConfig.defaultEmptyTheme.buttonSpacing;

  EdgeInsets get descMargin =>
      _descMargin ?? HcDefaultThemeConfig.defaultEmptyTheme.descMargin;

  EdgeInsets get titleMargin =>
      _titleMargin ?? HcDefaultThemeConfig.defaultEmptyTheme.titleMargin;

  EdgeInsets get imageMargin =>
      _imageMargin ?? HcDefaultThemeConfig.defaultEmptyTheme.imageMargin;

  EdgeInsets get padding =>
      _padding ?? HcDefaultThemeConfig.defaultEmptyTheme.padding;

  EdgeInsets get descPadding =>
      _descPadding ?? HcDefaultThemeConfig.defaultEmptyTheme.descPadding;

  EdgeInsets get titlePadding =>
      _titlePadding ?? HcDefaultThemeConfig.defaultEmptyTheme.titlePadding;

  EdgeInsets get imagePadding =>
      _imagePadding ?? HcDefaultThemeConfig.defaultEmptyTheme.imagePadding;
}
